Learning Objectives

After completing this lesson, you'll be able to:

In this lesson, you will:

Resources

Dynamic Tool Calls

In the previous lesson, an AI connector analyzed the List Tools response and selected a tool for the user's request. To complete the workflow, a second MCPCaller uses Call Tool to execute that tool, passing in the tool name and inputs from the AI output. The second MCPCaller returns a structured output that the rest of the workspace can continue processing. 

Together, the full workflow looks like this: an MCPCaller lists the tools, an AI connector selects the tool and formats its input, and a second MCPCaller calls the selected tool.

This approach means the workspace doesn't need an MCPCaller for each MCP tool, and you don't need to update it each time a new tool is added to the MCP server or a tool's inputs change. AI enhances the workflow by dynamically discovering and evaluating tools, making it adaptable as the MCP server evolves. 

The MCP Tool Response

When an MCP server runs a tool, it returns a result in JSON. With Include Response JSON enabled, the MCPCaller stores this result in the _json_response attribute. The result follows the structure the MCP specification defines:

Many tools return their data as JSON written inside the text property. Parsing the response is a two-stage process: first, extract the text from the content array, then parse that text as JSON to get the individual values. FME's JSON transformers, such as the JSONFragmenter, JSONFlattener, and JSONExtractor, handle both stages.

The content array has the same shape for every tool, but the JSON inside the text depends on which tool was called. Two tools on the same server can return completely different fields, so a dynamic workflow has to handle more than one response structure.

Exercise

Note

This exercise continues where the Use AI to Select MCP Tools exercise left off. You should complete the previous exercise before continuing with this one.

Frank, a GIS Administrator, has a workspace in which an AI connector selects a weather MCP tool and formats its input from a user's request. He now needs a single MCPCaller to call whichever tool the AI selects and return the weather data, so the workspace keeps working as tools are added to the server. Eventually, Frank can integrate this workspace with his future utility data MCP server to provide real-time weather metrics alongside some utility data workflows.

In this exercise, you will:

1) Open Starting Workspace

2) Edit the Call Tool MCPCaller

The Call Tool MCPCaller takes the tool_name and tool_input attributes from the OpenAIConnector output in place of a hardcoded tool. 

3) Add a JSONFragmenter

The MCPCaller returns structured JSON containing the MCP tool's response. To extract specific values into attributes, you need to parse the JSON.

4) Run the Workspace

You've connected to the weather MCP server, listed the server's available MCP tools, and called tools, both statically and dynamically. Throughout these exercises, you used FME as an MCP client, connecting to the MCP server, calling tools, and receiving MCP responses. 

Tips and Tricks: Use the JSON Response in Your Workspace